package com.five.dao.impl.backstage;

import com.five.dao.backstage.RuZhuDetaDao;
import com.five.entity.backstage.RuZhuDetail;
import com.five.util.DBUtil;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @ClassName RuZhuDetaDaoImpl
 * @Description TODO
 * @Author yuanshuaiqiang
 * @Date 2020/12/2 15:58
 */
@Repository
public class RuZhuDetaDaoImpl implements RuZhuDetaDao {
    @Override
    public List<Map> queryAll(Integer page, Integer limit, RuZhuDetail ruZhuDetail) {
        String sql="select * from t_ruzhudetail where 1=1 ";
        if (ruZhuDetail.getName()!=null && ruZhuDetail.getName()!=""){
            sql+=" and name like '%"+ruZhuDetail.getName()+"%' ";
        }
        if (ruZhuDetail.getTel()!=null){
            sql+=" and tel="+ruZhuDetail.getTel()+" ";
        }
        sql+=" limit ?,?";
        List<Map> maps = DBUtil.queryMap(sql,(page-1)*limit,limit);
        return maps;
    }

    @Override
    public int getcount(RuZhuDetail ruZhuDetail) {
        String sql="select count(*) a from t_ruzhudetail where 1=1 ";
        if (ruZhuDetail.getName()!=null && ruZhuDetail.getName()!=""){
            sql+=" and name like '%"+ruZhuDetail.getName()+"%' ";
        }
        if (ruZhuDetail.getTel()!=null){
            sql+=" and tel="+ruZhuDetail.getTel()+" ";
        }
        List<Map> maps = DBUtil.queryMap(sql);
        String s = maps.get(0).get("a") + "";
        int i = Integer.parseInt(s);
        return i;
    }
}
